//
//  PersonalCenterViewController.m
//  ForengnMenu
//
//  Created by wenzhaoxu on 16/1/14.
//  Copyright © 2016年 余旺. All rights reserved.
//

#import "PersonalCenterViewController.h"
#import "PersonalCenterTableViewCell.h"


@interface PersonalCenterViewController ()<UITableViewDataSource,UITableViewDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,PersonalCenterTableViewCellDelegate>

@property (weak, nonatomic) IBOutlet UIImageView *personalCenterBGImageView;

@property NSArray * titles;

@property NSArray * subTitles;

@property UIImageView * myHeadImageView;

@end

@implementation PersonalCenterViewController



- (void)viewDidLoad {
    [super viewDidLoad];

    UIButton * rightBnt = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBnt.frame = CGRectMake(0, 0, 60, 30);
    [rightBnt setImage:[UIImage imageNamed:@"iconfont-fanhui"] forState:UIControlStateNormal];
    [rightBnt setTitle:@"返回" forState:UIControlStateNormal];
    [rightBnt addTarget:self action:@selector(returnAction) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBnt];
    
    
    UIButton * moretBnt = [UIButton buttonWithType:UIButtonTypeCustom];
    moretBnt.frame = CGRectMake(0, 0, 60, 30);
    [moretBnt setTitle:@"更多" forState:UIControlStateNormal];
    [moretBnt addTarget:self action:@selector(moreAction) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:moretBnt];


        
    UILabel * l = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 80, 40)];
    l.text = @"个人中心";
    l.textAlignment = NSTextAlignmentCenter;
    l.textColor = [UIColor whiteColor];
    self.navigationItem.titleView = l;
    
    
    self.personalCenterBGImageView.image = [UIImage imageNamed:@"PersonalCenterBgImage.png"];
    
    self.titles = @[@"账号信息：",@"个性签名：",@"我的二维码"];
    self.subTitles = @[@"15802589359",@"嘴馋勤做菜，人丑多读书...",@""];

}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [picker dismissViewControllerAnimated:YES completion:^{
        
    }];
    
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
    
    self.myHeadImageView.image = image;

}


-(void)setAction{
    //警告视图
    UIAlertController * alertCtr = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction *firstAction = [UIAlertAction actionWithTitle:@"从本地选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        
        // 跳转到相机或相册页面
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.delegate = self;
        imagePickerController.allowsEditing = YES;
        imagePickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        
        [self presentViewController:imagePickerController animated:YES completion:^{
            
            
        }];
    }];
    
    UIAlertAction *secondAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        
        
    }];
    
    UIAlertAction *thirdAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
    }];
    
    
    [alertCtr addAction:firstAction];
    
    [alertCtr addAction:secondAction];
    
    [alertCtr addAction:thirdAction];
    
    [self presentViewController:alertCtr animated:YES completion:^{}];

}


-(void)returnAction{
    
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

-(void)moreAction{
 
    [self performSegueWithIdentifier:@"showMore" sender:nil];

}

//当界面消失之前调用
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    //让分割线透明
    [self.navigationController.navigationBar setShadowImage:[UIImage imageNamed:@""]];
    
}

//视图将要出现时
-(void)viewWillAppear:(BOOL)animated{
    
    //让导航栏透明
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];

    //让分割线透明
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    
}

//视图消失完毕后
-(void)viewDidDisappear:(BOOL)animated{
    
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}];
    
}

- (IBAction)returnBnt:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }else{
        return 3;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 130;
    }else{
        return 47;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * identifier;
    if (indexPath.section == 0) {
        identifier = @"cell0";
        
    }else{
        identifier = @"cell1";
    }
    PersonalCenterTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    cell.nameLabel.text = @"没什么特长";
    cell.sexLabel.text = @"女 19岁 湖南 长沙";
    
    cell.titleLabel.text = self.titles[indexPath.row];
    cell.subTitleLabel.text = self.subTitles[indexPath.row];
    
    cell.delegate =self;
    
    return cell;
    
}

//点击时触发
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //取消选择状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}




@end
